/**
* @file entity.h
* @brief 实体类
*/
#ifndef _SCENE_SERVICE_ENTITY_H_
#define _SCENE_SERVICE_ENTITY_H_

#include "../share/object.h"
#include "../share/geometry.h"
#include "../share/list_link.h"

#include "obj_define.h"
#include "FightProperty.h"
#include "GameObject.h"


/**
* @brief 实体基类(场景上所有可以被看见的都是实体)
*/
class CEntity :
	public ::common::CObj,public GameObject
{
public:
	CEntity();
	virtual ~CEntity();

	virtual int32_t Initialize() { return 0; }
	virtual int32_t Resume() { return 0; }

	virtual void TickUpdate() { }

	EObjType GetEntityType() { return  (EObjType)::common::CObj::ID2TYPE(get_id()); }

	int64_t instance_id() const { return instance_id_; }
	void set_instance_id(int64_t instance_id) { instance_id_ = instance_id; }

	const ::common::CVector3& position() const { return position_; }
	void set_position(const ::common::CVector3& position) { position_ = position; }

	float angle() const { return angle_; }
	void set_angle(float angle) { angle_ = angle; }

	float cur_speed() const { return cur_speed_; }
	void set_cur_speed(float cur_speed) { cur_speed_ = cur_speed; }

	::common::CListLink< CEntity >& entity_link() { return entity_link_; }

	virtual void SerialToJson(Json::Value& pb_entity) = 0;

	void set_orientation(float ox, float oy, float oz) { m_orientation_x = ox, m_orientation_y = oy, m_orientation_z = oz; }
	float orientation_x() { return m_orientation_x; }
	float orientation_y() { return m_orientation_y; }
	float orientation_z() { return m_orientation_z; }
	int32_t GetSceneId();
	virtual bool IsDeaded() { return false; }
	bool attackable() { return true; }

	FightProperty& GetFightProperty(void) { return m_fight_property; }

	void SetViewRange(double val)
	{
		m_view_range = val;
		m_sqr_view_range = val * val;
	}

	double GetViewRange(void) { return m_view_range; }
	double GetViewRangeSqr(void) { return m_sqr_view_range; }
// access_variable
public:
	// access_variable(double, Speed, m_speed);
	void SetSpeed(double m_speed_var) { m_speed = m_speed_var; }
	double GetSpeed() { return m_speed; }

	access_variable(uint32_t, TypeId, m_type_id);
	access_variable(double, OrientationX, m_orientation_x);
	access_variable(double, OrientationY, m_orientation_y);
	access_variable(double, OrientationZ, m_orientation_z);
protected:
	int64_t instance_id_;/**<地图实例id  */
	::common::CVector3 position_;/**<坐标  */
	float angle_;/**<朝向  */
	::common::CListLink< CEntity > entity_link_;
	float cur_speed_;/**<当前速度  */
	float		m_orientation_x;		//	朝向x
	float		m_orientation_y;		//	朝向y
	float		m_orientation_z;		//	朝向z
public:
	void SetKey(uint32_t client_key) { client_key_ = client_key; }
	uint32_t GetKey() { return client_key_; }
	FightProperty& GetFightPro(void) { return m_fight_property; }
	void SetClientType(int32_t type) { obj_type_ = type; }
	int32_t GetClientType() { return obj_type_; }
private:
	uint32_t client_key_;
	FightProperty m_fight_property;
	int32_t obj_type_;	//跟客户端通信的type
	double m_view_range;
	double m_sqr_view_range;

	// access_variable 属性
private:
	double m_speed;
	uint32_t m_type_id;
};



#endif

